<?php


namespace App\Http\Controllers\admin\model;

use Illuminate\Support\Facades\DB;

/**
 * 专题
 * Class TopIcModel
 * @package App\Http\Controllers\admin\model
 */
class TopIcModel
{
    public static function add($param){
        return DB::table('t_topic')->insert($param);
    }

    public static function edit($where,$param){
        return DB::table('t_topic')->where($where)->update($param);
    }

    public static function queryFirst($where,$field){
        return DB::table('t_topic')->where($where)->first($field);
    }

    public static function delete($where){
        return DB::table('t_topic')->where($where)->delete();
    }

    public static function queryCount($where=[],$param=[]){
        if(isset($param['type']) && $param['type']!=1){
            return DB::table('t_topic')
                ->where($where)
                ->where("$param[field]",'like','%'.$param["$param[field]"].'%')
                ->count('id');
        }
        return DB::table('t_topic')
            ->where($where)
            ->count('id');
    }

    public static function queryAll($where=[],$param=[],$page){
        $field = ['id','name','img_url','grade_id','status','create_time','update_time'];
        if(isset($param['type']) && $param['type']!=1){
            return DB::table('t_topic')
                ->where($where)
                ->where("$param[field]",'like','%'.$param["$param[field]"].'%')
                ->offset($page['startSize'])
                ->limit($page['pageSize'])
                ->get($field);
        }
        return DB::table('t_topic')
            ->where($where)
            ->offset($page['startSize'])
            ->limit($page['pageSize'])
            ->get($field);
    }

    public static function queryLikeFirst($where,$andWhere,$field){
        return DB::table('t_topic')
            ->where($where)
            ->where("$andWhere[field]",'like','%'.$andWhere["$andWhere[field]"].'%')
            ->first($field);
    }
}